﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Willow.IService.Sys;
using Willow.MVC.Search;

namespace Willow.WebApplication.Areas.Sys.Controllers
{
    public class LoginLogController : Controller
    {

        ILoginLogService LoginLogService { get; set; }

        public LoginLogController(ILoginLogService loginLogService)
        {
            this.LoginLogService = loginLogService;
        }

        #region 页面

        /// <summary>
        /// 登录日志列表页
        /// </summary>
        /// <returns></returns>
        public ViewResult List()
        {
            return View();
        }

        #endregion

        #region 操作

        /// <summary>
        /// 获取登录日志分页后信息
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="orgId">The org identifier.</param>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public JsonResult GetPagedList(int page, int rows, string orgId, QueryModel query)
        {
            int total = 0;
            var filter = LoginLogService.Query(p => true);
            var lstData = filter
                .OrderByDescending(p => p.LoginTime)
                .Where(query, page, rows, out total)
                .Select(p => new
                {
                    p.UserName,
                    p.Ip,
                    p.Successful,
                    p.LoginTime,
                    p.Remark
                }).ToList();

            return Json(new { rows = lstData, total }, JsonRequestBehavior.AllowGet);
        }

        #endregion

    }
}